export {};

/**
 * 类 Class
 *
 * public -> 公共的
 * private -> 私有的 只能在自身访问
 * protected -> 受保护的 只能在自身和子类访问
 */

class Person {
    public name: string;
    private age: number;
    protected sex: string;
    constructor(name: string, age: number, sex?: string) {
        this.name = name;
        this.age = age;
        this.sex = sex || "女";
    }

    sayHi(msg: string): void {
        console.log(`${this.name}:${this.age} => ${msg}`);
    }
}

const tom = new Person("tom", 21, "男");
console.log(tom.name);
//  console.log(tom.age); // 'age' is private
tom.sayHi("aaa");

class Student extends Person {
    private constructor(name: string, age: number) {
        super(name, age);
        console.log(this.sex);
    }
    static create(name: string, age: number) {
        return new Student(name, age);
    }
}

//  const jack = new Student() // Constructor of class 'Student' is private
const jack = Student.create('jack', 18)